<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="com.sims.user.UserDAO"%>
<%@ page import="com.sims.vo.UserInfo"%>
<%@ page import="java.util.ArrayList"%>

<html>
<head>
	<title>学生信息管理系统</title>
	
	<link rel="stylesheet" href="/sims/css/sims_main.css" type="text/css" />
	<link rel="stylesheet" href="/sims/css/sims_tab.css" type="text/css" />
	<link rel="stylesheet" href="/sims/css/sims_table.css" type="text/css" />

	<script type="text/javascript" src="/sims/js/sims.js" charset="GBK"></script>
	
</head>

<body>
		<% 
		    String userName=(String)session.getAttribute("username");
			int[] userrights = (int[])session.getAttribute("userrights");
			String currentPage=(String)session.getAttribute("currentPage");
			UserDAO ud = new UserDAO();
			
		    if (userName != null && ud.checkUserInfo(userName))
		    {
		    	//计算分页个数
				int nums = Integer.parseInt(ud.queryCount());
				int counts = 0;
				if (nums%10 > 0)
				{
					counts = nums/10 + 1;
				}
				else
				{
					counts = nums/10;
				}
				
				if (currentPage==null)
				{
					currentPage = "1";
				}
		%>
		    	<div id="header">
				<span id="logoTxt" class="logo">&nbsp;学生信息管理系统</span>
				<span id="loginname" class="username">当前用户：
				<%
					out.println(userName);
				%>
				&nbsp;&nbsp;</span>
				<a class="logout" href="/sims/pages/logout.jsp">注销</a>
				</div>

				<div id="menu">
				<ul id="tab">
					<% 
						if (userrights[0]==1)
						{
					%>
					<li><a href="/sims/pages/default.jsp">信息管理</a></li>
					<% 
						}
						if (userrights[1]==1)
						{
					%>
					<li><a href="/sims/pages/changepwd.jsp">密码管理</a></li>
					<% 
						}
						if (userrights[2]==1)
						{
					%>
					<li><a href="/sims/pages/right.jsp">权限管理</a></li>
					<% 
						}
					%>
				</ul>
				</div>

				<div id="content">
				
				<form name="queryusers" method="POST">
				
				<table align = "left" > 
          		<tr>
          			<%
          			if (userrights[2]==1)
						{
					%>
         			<td><input type ="button" value ="新增用户"  onClick="location.href='/sims/pages/creatuser.jsp'" style="margin-left: 10px;"/></td>
         			<td><input type ="button" name="batchdelete" value ="批量删除"  onClick="batchDeleteUser('userc')"/></td>
         			<% 
					}
          			else
          			{
          			%>
          				<td></td>
          			<% 
          			}
					%>
         		</tr>
     			</table>
				
         		<table class="dataintable">
             	<tr align="center">
                 	<th><input type="checkbox" name="deletenum" onclick="check_all(this,'userc')"/>全选</th>
                 	<th>学号</th>
                 	<th>姓名</th>
                 	<th>性别</th>
                 	<th>学院</th>
                 	<th>专业</th>
                 	<th>账号类型</th>
                 	<%
          			if (userrights[2]==1)
						{
					%>
                	<th colspan="2">操作</th>
                	<% 
						}
					%>
            	</tr>
           
            	<%
            	ArrayList<UserInfo> userInfos = ud.queryUserInfos(currentPage);
            	for(int i = 0 ; i<userInfos.size();i++) 
            	{
            		UserInfo userInfo = userInfos.get(i);
               	%>
                <tr align="center" >
                	<td><input type="checkbox" value='<%=userInfo.getUserId()%>' name="userc"/></td>
                	<td><%=userInfo.getUserId()%></td>
                	<td><%=userInfo.getUserName()%></td>
                	<td><%=userInfo.getUserSex()%></td>
                	<td><%=userInfo.getUserCollage()%></td>
                	<td><%=userInfo.getUserSpecialty()%></td>
                	<td><%=ud.queryTypeNameByUserId(userInfo.getUserId())%></td>
                	<%
          			if (userrights[2]==1)
						{
					%>
                	<td><a href='javascript:deleteUserInfo("<%=userInfo.getUserId()%>")' style="text-decoration: none;">删除</a></td>
                	<td><a href="/sims/pages/updateUser.do?userId=<%=userInfo.getUserId()%>" style="text-decoration: none;">修改</a></td>
                	<% 
						}
					%>
            	</tr>
             	<%
             	}
             	%>
             	
             	<tr align="center">
                	<th colspan="9">
                	<%
                		for (int cpage = 1;cpage<=counts;cpage++)
                		{
                	%>
                		<a href='/sims/pages/changePage.do?cpage=<%=cpage%>' style="text-decoration: none;"><%=cpage%></a>
                	<%		
                		}
                	%>                	
                	</th>
            	</tr>
             	
         		</table>
     			
     			</form>
				
				</div>
				
				<script type="text/javascript">
				document.getElementsByTagName('div').innerHTML = "index.jsp";
    			</script>

				<div id="footer">Copyright no right</div>
				
				<% 
						String errMsg = (String)request.getSession().getAttribute("Message");
						if (errMsg != null)
						{
							out.println("<SCRIPT LANGUAGE='JavaScript'>");
							out.println("alert('"+errMsg+"')");
							out.println("</SCRIPT>");
							request.getSession().removeAttribute("Message");
						}
						else
						{
							out.println("");
						}
				%>
				<% request.getSession().removeAttribute("currentPage"); %>
				
		<%
		    }
		    else
		    {
		    	response.sendRedirect("/sims/index.jsp");
		    }
		%>		
</body>
</html>